package com.veal98.tree;

import com.veal98.bean.TreeNode;

public class SumOfLeftLeaves_404 {

    public int sumOfLeftLeaves(TreeNode root) {
        // 递归出口
        if (root == null) {
            return 0;
        }

        int leftLeafVal = 0;

        // 根
        if (root.left != null && root.left.left == null && root.left.right == null) {
            leftLeafVal = root.left.val;
        }
        // 左
        int leftSum = sumOfLeftLeaves(root.left);
        // 右
        int rightSum = sumOfLeftLeaves(root.right);

        return leftLeafVal + leftSum + rightSum;
    }


}